﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using LeeAnn;
using LeeAnn.FeedForward;
using LeeAnn.Framework;
using System.Collections;

namespace Demo2
{
    public partial class Form1 : Form
    {
        FeedForwardAnn fan;
        int curNum = 0;
        bool bRun = false;
        public Form1()
        {
            InitializeComponent();
            fan = new FeedForwardAnn(3, 1);
            ArrayList inouts = new ArrayList();
            for (int i = 0; i < fan.Width; i++)
            {
                inouts.Add(new FeedForwardNeuronPlaceholder(new Position3D(i, 0, 0)));
            }
            fan.addInputNeuron(inouts, new Neuron.CalculateIODelegate(fan.CalculateEvent));
            ArrayList outins = new ArrayList();
            for (int i = 0; i < fan.Width; i++)
            {
                outins.Add(new FeedForwardNeuronPlaceholder(new Position3D(i, fan.Height - 1, 0)));
            }
            fan.addOutputNeuron(outins, new Neuron.CalculateIODelegate(fan.CalculateEvent));
            fan.InputOutputNeurons[fan.Outputs[0]].OutputEvent += new Neuron.OutputDelegate(onOutput);
            fan.GetInputNeuron(0).Input(0);
            fan.Update();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 1500; i++)
            {
                double d = Math.Sqrt(Math.Pow(i, 2));
                label3.Text = d.ToString();
                this.Update();
            }
            fan.InputOutputNeurons[fan.Inputs[0]].Input(curNum);
            fan.Update();
        }
        private void onOutput(double data)
        {
            if (curNum == 1500)
            {
                curNum = 0;
                bRun = true;
                return;
            }
            double d = Math.Sqrt(Math.Pow(curNum, 2));
            if (data == d)
                fan.Reward();
            else
                fan.Punish();
                label4.Text = data.ToString();
                this.Update();
            curNum++;
            fan.InputOutputNeurons[fan.Inputs[0]].Input(curNum);
            fan.Update();
        }
    }
}
